<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>机构管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			layui.use(['laypage', 'form'], function(){
				form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
				form.render();
			});	
			$("#inputForm").validate({
				submitHandler: function(form){
					$('#btnSubmit').blur();//去除提交按钮焦点  防止提示错误点击空格 及回车 后继续提交
					//电话号验证
					function checkContactNumberPhone(number) {  
				        var isPhone = /^0\d{2,3}-?\d{7,8}$/;
				        //如果为1开头则验证手机号码  
				        if (number.substring(0, 1) == 0) {  
				            if (!isPhone.test(number)) {   
				                return false;  
				            }  
				        }  else {  
				            return false;  
				        } 
				        return true;  
					};
					function checkContactNumberFax(number) {  
				       var isFax =/^0\d{2,3}-?\d{7,8}$/;  
				        //如果为1开头则验证手机号码  
				        if (number.substring(0, 1) == 0) {  
				            if (!isFax.test(number)) {   
				                return false;  
				            }  
				        }  else {  
				            return false;  
				        } 
				        return true;  
					};
					
					if($("#phone").val() != "" && !checkContactNumberPhone($("#phone").val())){
                    	layer.alert("联系电话输入错误，请正确填写！", {icon: 0});
                   		 return false;
               		 }
					if($("#fax").val() != "" && !checkContactNumberFax($("#fax").val())){
                    	layer.alert("传真输入错误，请正确填写！", {icon: 0});
                   		 return false;
               		 }
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		}); 
	</script>
	
</head>
<body>
	<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
	<ul class="layui-tab-title">
		<li><a href="${ctx}/sys/office/list?id=${office.parent.id}&parentIds=${office.parentIds}">机构列表</a></li>
		<li class="layui-this"><a href="${ctx}/sys/office/form?id=${office.id}&parent.id=${office.parent.id}">机构<shiro:hasPermission name="sys:office:edit">${not empty office.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:office:edit">查看</shiro:lacksPermission></a></li>
	</ul>
	<div class="layui-tab-content"></div>
	</div><br/>
	<form:form id="inputForm" modelAttribute="office" action="${ctx}/sys/office/save" method="post" class="layui-form">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">上级机构:</label>
			<div class="layui-input-inline">
                <sys:treeselect id="office" name="parent.id" value="${office.parent.id}" labelName="parent.name" labelValue="${office.parent.name}"
					title="机构" url="/sys/office/treeData" extId="${office.id}" cssClass="layui-input" allowClear="${office.currentUser.admin}"/>
			</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">归属区域:</label>
			<div class="layui-input-inline">
                <sys:treeselect id="area" name="area.id" value="${office.area.id}" labelName="area.name" labelValue="${office.area.name}"
					title="区域" url="/sys/area/treeData" cssClass="required layui-input"/>
			</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">机构名称:</label>
			<div class="layui-input-inline">
				<form:input path="name" htmlEscape="false" maxlength="50" class="required layui-input"/>
			</div>
				<span class="layui-form-mid"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">机构编码:</label>
			<div class="layui-input-inline">
				<form:input path="code" htmlEscape="false" maxlength="50" class="layui-input"/>
			</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">机构类型:</label>
			<div class="layui-input-inline">
				 <select id="office_type" name="type" data-value="" >
	                    <option value="" ${office.type==''?'selected':''}></option>
	                    <c:forEach items="${fns:getDictList('sys_office_type')}" var="dict">
	                        <option value="${dict.value}" ${dict.value==office.type?'selected':''}>${dict.label}</option>
	                    </c:forEach>
	         	</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">机构级别:</label>
			<div class="layui-input-inline">
			 	<select id="office_grade" name="grade" data-value="" >
			 			<option value="" ${office.grade==''?'selected':''}></option> 
	                    <c:forEach items="${fns:getDictList('sys_office_grade')}" var="dict">
	                        <option value="${dict.value}" ${dict.value==office.grade?'selected':''}>${dict.label}</option>
	                    </c:forEach>
				 </select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">是否可用:</label>
			<div class="layui-input-inline">
				<select id="office_useable" name="useable" data-value="" >
			 	<option value="" ${office.useable==''?'selected':''}></option>
	                    <c:forEach items="${fns:getDictList('yes_no')}" var="dict">
	                        <option value="${dict.value}" ${dict.value==office.useable?'selected':''}>${dict.label}</option>
	                    </c:forEach>
				 </select>
			</div>
		</div>
		
		
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">主负责人:</label>
			<div class="layui-input-inline">
				 <sys:treeselect id="primaryPerson" name="primaryPerson.id" value="${office.primaryPerson.id}" labelName="office.primaryPerson.name" labelValue="${office.primaryPerson.name}"
					title="用户" url="/sys/office/treeData?type=3"  cssClass="layui-input" allowClear="true" notAllowSelectParent="true"/>
			</div>
			</div>
		</div>
		
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">副负责人:</label>
			<div class="layui-input-inline">
				 <sys:treeselect id="deputyPerson" name="deputyPerson.id" value="${office.deputyPerson.id}" labelName="office.deputyPerson.name" labelValue="${office.deputyPerson.name}"
					title="用户" url="/sys/office/treeData?type=3" allowClear="true" cssClass="layui-input" notAllowSelectParent="true"/>
			</div>
			</div>
		</div>
		
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">联系地址:</label>
			<div class="layui-input-inline">
				<form:input path="address" htmlEscape="false" maxlength="50" class="layui-input"/>
			</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">邮政编码:</label>
			<div class="layui-input-inline">
				<form:input path="zipCode" htmlEscape="false" maxlength="50" class="layui-input"/>
			</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">负责人:</label>
				<div class="layui-input-inline">
				<form:input path="master" htmlEscape="false" maxlength="50" class="layui-input"/>
			</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">电话:</label>
			<div class="layui-input-inline">
				<form:input path="phone" id="phone" htmlEscape="false" maxlength="50" class="layui-input"/>
				
			</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">传真:</label>
			<div class="layui-input-inline">
				<form:input path="fax" id = "fax" htmlEscape="false" maxlength="50"  class="layui-input"/>
			</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">邮箱:</label>
			<div class="layui-input-inline">
				<form:input path="email" htmlEscape="false" class="layui-input" lay-verify="email"/>
			</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
			<label class="layui-form-label">备注:</label>
			<div class="layui-input-inline">
				<form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="layui-textarea"/>
			</div>
			</div>
		</div>
		<div class="layui-form-item">
		 	<label class="layui-form-label">快速添加下级部门:</label>
				<div class="layui-input-block">
						<c:forEach items="${fns:getDictList('sys_office_common')}" var="dict" varStatus="dictStatus">
	                         <span><input id="childDeptList${dictStatus.index}"  name="childDeptList" type="checkbox" value="${dict.value}" data-value="" title="${dict.label}" ></span>
	                    </c:forEach>
				</div>
		</div>
		
		
		<div class="layui-form-item">
			<div class="layui-input-block">
			<shiro:hasPermission name="sys:office:edit"><input id="btnSubmit" class="layui-btn" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="layui-btn layui-btn-primary" type="button" value="返 回" onclick="history.go(-1)"/>
			</div>
		</div>
	</form:form>
</body>
</html>